package com.android.mybase.base

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding

abstract class BaseActivity<T : ViewBinding>: AppCompatActivity() {
    lateinit var binding: T

    companion object {
        inline fun <reified A : BaseActivity<*>> goTo(context: Context) {
            val intent = Intent(context, A::class.java)
            context.startActivity(intent)
        }

        // 如果需要传递额外参数
        inline fun <reified A : BaseActivity<*>> goTo(
            context: Context,
            block: Intent.() -> Unit
        ) {
            val intent = Intent(context, A::class.java)
            intent.block()
            context.startActivity(intent)
        }
    }
    abstract fun getBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): T

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        this.enableEdgeToEdge()
        binding = getBinding(LayoutInflater.from(this), null)
        setContentView(binding.root)
    }

}